# Python 2.6.4
# Project Euler, Problem 4
# Copyright 2010 Talha Zaman

from common import timed

@timed
def palindrome(digits):
    begin = 10 ** (digits-1)
    end = 10 * begin
    maxpal=0
    for i in xrange(begin, end):
        for j in xrange(begin, end):
            ij = str(i*j)
            if (ij == ij[::-1]):
                pal = int(ij)
                if (maxpal < pal): maxpal = pal
    return maxpal

if __name__ == '__main__':
    print palindrome(3)